home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / proto-kit / Makefile < prev    next >
Makefile  |  1991-06-28  |  13KB  |  380 lines

  1. #******************************************************************************
  2. #  This GNUmakefile is useful for large and complex projects which involve
  3. # both G++ library prototypes, and prototypes added by the user(s).  It 
  4. # is assumed that certain conventions are followed.
  5. #
  6. # 1) each object has its own source and header files.  For example class W 
  7. #    would have W.h and W.cc
  8. #
  9. # 2) each prototype object has its own source and header files (W.hP and W.ccP)
  10. #
  11. # 3) object header files are contained in directory $(IDIR) (for Include
  12. #    DIRectory)
  13. #
  14. # 4) object source files are contained in the current directory
  15. #
  16. # 5) prototype instantiations are contained in $(PC) (for Prototype C++
  17. #    directory)
  18. #
  19. # 6) user prototype files (both header and source) are contained in $(IPP)
  20. #
  21. # 7) non-class code is contained in .h and .cc files, which live in $(IDIR)
  22. #    and the current directory respectively
  23. #
  24. # *) as an extra, I have added the convention that whenever a W.cc file
  25. #    is being compiled, the macro _W_cc is defined.  This is useful
  26. #    particularly for conditional parts of header files (for example,
  27. #    W.h could have ifdef _W_cc ...
  28. #
  29. # The makefile works in the following manner: the source dependencies are
  30. # contained in .Makefile.S_DEP, while the (machine generated) object 
  31. # dependencies are contained in .Makefile.O_DEP.  The types needed by
  32. # the program are defined by several variables, and the makefile generates
  33. # the necessary dependencies (both source and object) from those variables.
  34. # The prototype lists are contained in .Makefile.TYPES.
  35. # NOTE: in order to create the machine generated files .Makefile.TYPES,
  36. #  .Makefile.S_DEP, and .Makefile.O_DEP, empty versions of these
  37. #  file must exist.  They can be easily created using "touch <file>".
  38. #
  39. #  -- Carl Staelin
  40. #     staelin@princeton.edu
  41. #******************************************************************************
  42.  
  43. #******************************************************************************
  44. # standard Makefile definitions
  45.  
  46. comma := ,
  47. space := $(empty) $(empty)
  48. tab := $(empty)    $(empty)
  49.  
  50. #******************************************************************************
  51. # definitions from environment variables
  52.  
  53. # the CPATH include directories 
  54. cpath-include-directories := $(addprefix -I, $(subst :,$(space),$(CPATH)))
  55.  
  56. # the LPATH load directories 
  57. lpath-load-directories := $(addprefix -L, $(subst :,$(space),$(LPATH)))
  58.  
  59. #******************************************************************************
  60. # Basic definitions
  61.  
  62. HOST := $(shell hostname)
  63.  
  64. BASE := 
  65.  
  66. # CMU Directories
  67. USR  := $(BASE)/usr
  68. MACH := $(BASE)/usr/mach
  69. CS   := $(BASE)/usr/cs
  70.  
  71. # GNU directories
  72. GNULIBDIR := $(BASE)/usr/local/lib
  73. GNUIDIR := $(GNULIBDIR)/g++-include
  74.  
  75. # the g++ library prototypes...
  76. LPP := $(GNUIDIR)
  77. PC := ../libg++
  78.  
  79. # the user's library prototypes...
  80. IPP := ../proto
  81.  
  82. # the include directory
  83. IDIR := ../include
  84.  
  85. # the include directories needed...
  86. IDIRS := -I$(IDIR) -I$(PC) -I$(GNUIDIR) $(cpath-include-directories) 
  87.  
  88. # the directories where the libraries live...
  89. LDIRS := $(lpath-load-directories)
  90.  
  91. #******************************************************************************
  92. # standard function (and associated variables) definitions
  93.  
  94. C++ = g++
  95. C++FLAGS = -pipe -O $(IDIRS) 
  96.         -Dc_plusplus \
  97.         -DDEBUG \
  98.         -D$(strip $(subst .,_, _$(basename $(@F))_cc)) 
  99.  
  100.  
  101. GENCLASS = ../bin/genclass.extnsn
  102. PREPEND  = ../bin/prepend
  103. HIERARCHY    = ../bin/hierarchy
  104. MAKE_TYPES    = ../bin/make-types
  105. PROTOTYPE    = ../bin/prototype
  106.  
  107. #******************************************************************************
  108. # implicit rules
  109.  
  110. %.o : %.cc
  111.     $(C++)    $(C++FLAGS) \
  112.         -c -o $@ $(@D)$(basename $(@F)).cc
  113.  
  114. #******************************************************************************
  115. # User types
  116.  
  117. BASIC_TYPES = \
  118.     int \
  119.     u_int \
  120.     l_int \
  121.     l_u_int 
  122.  
  123. # generated by this make file (initially create an empty .Makefile.TYPES
  124. # so that "make dependencies" can create the real file)
  125. include .Makefile.TYPES
  126.  
  127. #******************************************************************************
  128. # User types (with sample values filled in) 
  129. # NOTE: do NOT add .h to the end of these, MAKE does it for you!
  130.  
  131. HEADER_FILES = \
  132.     disk_set \
  133.     file_types \
  134.     include \
  135.     inode \
  136.     inode_t \
  137.     lib \
  138.     main \
  139.     nfs_functions \
  140.     nfs_mount \
  141.     nfs_params \
  142.     nfs_prot \
  143.     system 
  144.  
  145. SOURCE_FILES = \
  146.     disk_set \
  147.     lib \
  148.     nfs_auxil \
  149.     nfs_dirent \
  150.     nfs_fh \
  151.     nfs_ipcress \
  152.     nfs_links \
  153.     nfs_main \
  154.     nfs_mnt_serv \
  155.     nfs_mount_xdr \
  156.     nfs_prot_xdr \
  157.     nfs_serv1 \
  158.     nfs_serv2 \
  159.     nfs_serv3 \
  160.     nfs_serv4 \
  161.  
  162. #******************************************************************************
  163. # some sample machine generated user-file stuff
  164. #
  165. ../include/file_types.h : ../include/file_types.type.h ../include/file_types.operation.h
  166. ../include/Substrate_file.h : ../include/file_types.includes.h
  167.  
  168. ../include/file_types.type.h : ../include/file_types.hierarchy
  169.     $(HIERARCHY) -voutput_type=type ../include/file_types.hierarchy > $@
  170.  
  171. ../include/file_types.includes.h : ../include/file_types.hierarchy
  172.     $(HIERARCHY) -voutput_type=general -vpreamble='#include "' \
  173.         -vpostamble='.h"' -vprint_first=1 ../include/file_types.hierarchy > $@
  174.  
  175. ../include/file_types.operation.h : ../include/file_types.hierarchy
  176.     (echo '#define FILE_TYPES_OPERATION(OPERATION)  \' ; \
  177.      $(HIERARCHY) -voutput_type=general -vpreamble='OPERATION(' \
  178.         -vpostamble=') \' -vprint_first=1 ../include/file_types.hierarchy ; \
  179.      echo ; ) | sed 's/\.//g' > $@ ;
  180.  
  181. #******************************************************************************
  182. # source files...
  183.  
  184. HEADERS := $(wildcard $(addprefix $(IDIR)/, $(addsuffix .h, $(USER_TYPES) $(HEADER_FILES))))
  185.  
  186. SOURCES := $(wildcard $(addsuffix .cc, $(USER_TYPES) $(SOURCE_FILES)))
  187.  
  188. OBJECTS := $(patsubst %.cc,%.o,$(SOURCES))
  189.  
  190. #******************************************************************************
  191. # User prototype instantiations
  192.  
  193. USER_PROTO_HEADERS := $(addprefix $(PC)/, $(addsuffix .h, $(foreach type, $(basename $(notdir $(wildcard $(addprefix $(IPP)/, $(addsuffix .hP, $(USER_BASE_PROTO_TYPES)))))), $(filter %.$(type), $(USER_PROTO_TYPES)))))
  194.  
  195. USER_PROTO_SOURCES := $(addprefix $(PC)/, $(addsuffix .cc, $(foreach type, $(basename $(notdir $(wildcard $(addprefix $(IPP)/, $(addsuffix .ccP, $(USER_BASE_PROTO_TYPES)))))), $(filter %.$(type), $(USER_PROTO_TYPES)))))
  196.  
  197. USER_PROTO_OBJECTS := $(patsubst %.cc, %.o, $(USER_PROTO_SOURCES))
  198.  
  199. USER_PROTO_TYPE_SOURCES := $(wildcard $(addprefix $(IPP)/, $(addsuffix .hP, $(USER_BASE_PROTO_TYPES)) $(addsuffix .ccP, $(USER_BASE_PROTO_TYPES))))
  200.  
  201. #******************************************************************************
  202. # libg++ prototype instantiations
  203.  
  204. LIB_PROTO_HEADERS := $(addprefix $(PC)/, $(addsuffix .h, $(foreach type, $(basename $(notdir $(wildcard $(addprefix $(LPP)/, $(addsuffix .hP, $(LIB_BASE_PROTO_TYPES)))))), $(filter %.$(type), $(LIB_PROTO_TYPES)))))
  205.  
  206. LIB_PROTO_SOURCES := $(addprefix $(PC)/, $(addsuffix .cc, $(foreach type, $(basename $(notdir $(wildcard $(addprefix $(LPP)/, $(addsuffix .ccP, $(LIB_BASE_PROTO_TYPES)))))), $(filter %.$(type), $(LIB_PROTO_TYPES)))))
  207.  
  208. LIB_PROTO_OBJECTS := $(patsubst %.cc, %.o, $(LIB_PROTO_SOURCES))
  209.  
  210. .PHONY : test
  211. test :
  212.     @echo LIB_PROTO_TYPES = "${LIB_PROTO_TYPES}";
  213.     @echo LIB_BASE_PROTO_TYPES = "${LIB_BASE_PROTO_TYPES}" ;
  214.     @echo LIB_PROTO_OBJECTS = "${LIB_PROTO_OBJECTS}" ;
  215.     @echo LIB_PROTO_HEADERS = "${LIB_PROTO_HEADERS}" ;
  216.  
  217. #*****************************************************************************
  218. # main procedures..
  219.  
  220. # example:
  221. foo : foo.o $(OBJECTS) 
  222.     $(C++) $(C++FLAGS) -o $@ foo.o $(OBJECTS) $(LDIRS)
  223.  
  224. sources : $(SOURCES) 
  225.  
  226. #******************************************************************************
  227. # various cleanup stuff...
  228.  
  229. .PHONY : rmback clean realclean
  230.  
  231. rmback : 
  232.     cd .. ; rm -f proto/*~ include/*~ src/*~
  233.  
  234. clean : rmback
  235.     rm -f $(OBJECTS) $(PROTOLIB) $(LIB_PROTO_OBJECTS) $(USER_PROTO_OBJECTS)
  236.  
  237. realclean : clean
  238.     rm -f $(LIB_PROTO_SOURCES) $(USER_PROTO_SOURCES) $(LIB_PROTO_HEADERS) $(USER_PROTO_HEADERS)
  239.  
  240.  
  241. #*****************************************************************************
  242. # debugging actions
  243.  
  244. %.E : %.cc
  245.     $(C++) $(C++FLAGS) -E $(@D)$(basename $(@F)).cc > $@
  246.  
  247. %.s : %.cc
  248.     $(C++) -S $(C++FLAGS) $< -o $@
  249.  
  250. #******************************************************************************
  251. # "functions" for creating library source code from prototypes
  252.  
  253. parameters = $(subst .,$(space),$(notdir $(basename $(basename $@))))
  254. ifdef_filename = $(subst .,_,$(notdir $(basename $@)))
  255.  
  256. generic-type = $(subst .,,$(suffix $(basename $(notdir $@))))
  257.  
  258. #
  259. # return the type if it should be a "val" type (pointer or basic type)
  260. #
  261. parameter-val-q = $(filter %_p, $(parameter)) $(filter-out %_p, $(filter $(parameter), $(BASIC_TYPES)))
  262.  
  263. #
  264. # return the list of pairs of types and their prototype type (val or ref)
  265. #
  266. proto-type-arg = $(parameter) \
  267.     $(patsubst %, val, $(filter 1, $(words $(parameter-val-q)))) \
  268.     $(patsubst %, ref, $(filter-out 1, $(words $(parameter-val-q))))
  269.  
  270. define make-proto-file
  271. $(GENCLASS) \
  272.   $(dir $<) \
  273.   $(dir $@) \
  274.   $(suffix $@) \
  275.   $(foreach parameter, $(parameters), $(proto-type-arg)) \
  276.   $(generic-type) ;
  277. endef
  278.  
  279.  
  280. define prepend-proto-includes
  281. $(PREPEND) \
  282.   $(addsuffix .h, $(basename $@)) \
  283.   '#include "include.h"' \
  284.   $(patsubst %, '#include "%.h"', $(foreach type, $(USER_TYPES) $(USER_PROTO_TYPES) $(LIB_PROTO_TYPES), $(patsubst %, $(type), $(filter $(subst .,, $(type)), $(patsubst %_p, %, $(parameters)))))) ;
  285. endef
  286.  
  287. #******************************************************************************
  288. # libg++ prototype dependencies
  289.  
  290.  
  291. #
  292. # Used to automatically generate a %_p.defs file, which is required by classes
  293. # which do comparisons, for pointer types to objects which have the real 
  294. # comparison code.
  295. #
  296. # this will cat the appropriate strings 
  297. #
  298. $(addprefix $(PC)/, $(addsuffix .h, $(filter-out char_p.defs, $(filter %_p.defs, $(LIB_PROTO_TYPES))))) : 
  299.     @ echo creating $@ ; \
  300.     ( ifdef_filename=$(strip $(ifdef_filename)) \
  301.       p=$(strip $(patsubst %_p, %, $(parameters))) \
  302.       ../bin/make-defs-file ) > $@ ;
  303.  
  304. lib_proto_intermediate_sources = \
  305. $(filter-out %_p.defs.h, $(LIB_PROTO_HEADERS) $(LIB_PROTO_SOURCES)) \
  306. $(addprefix $(PC)/, $(addsuffix .h, char_p.defs)) 
  307.  
  308. lib_type_and_suffix_list = $(sort $(join $(suffix $(basename $(lib_proto_intermediate_sources))), $(addprefix ., $(suffix $(lib_proto_intermediate_sources)))))
  309.  
  310. #******************************************************************************
  311. # prototype dependencies
  312.  
  313. proto_intermediate_sources = \
  314.     $(USER_PROTO_HEADERS) \
  315.     $(USER_PROTO_SOURCES) 
  316.  
  317. type_and_suffix_list = $(sort $(join $(suffix $(basename $(proto_intermediate_sources))), $(addprefix ., $(suffix $(proto_intermediate_sources)))))
  318.  
  319. #******************************************************************************
  320. # generate machine generated dependencies 
  321.  
  322. H_FILES  = $(HEADERS) $(LIB_PROTO_HEADERS) $(USER_PROTO_HEADERS)
  323. CC_FILES = $(SOURCES) $(LIB_PROTO_SOURCES) $(USER_PROTO_SOURCES)
  324.  
  325. DEPENDENCIES = $(addsuffix .d, $(basename $(CC_FILES)))
  326.  
  327. $(addsuffix .d, $(basename $(CC_FILES))) : %.d : %.cc
  328.     ( echo -n $(@D) ; $(C++) -M $(C++FLAGS) $*.cc) > $@;
  329.  
  330. #******************************************************************************
  331. # machine generated type stuff
  332. #
  333.  
  334. $(DEPENDENCIES) : $(H_FILES)
  335.  
  336. .PHONY : dependencies source-dependencies object-dependencies 
  337.  
  338. dependencies : type-definitions source-dependencies
  339.     @ $(MAKE) object-dependencies 
  340.  
  341. object-dependencies : $(DEPENDENCIES) 
  342.     @echo making object dependencies... ; \
  343.     rm .Makefile.O_DEP ; \
  344.     ls . | grep '\.d$$' > /tmp/dependencies ; \
  345.     ls $(PC) | gawk '{printf "$(PC)/%s\n", $$0 ; }' | grep '\.d$$' >> \
  346.         /tmp/dependencies ; \
  347.     for file in `cat /tmp/dependencies` ; do \
  348.       cat $$file ; \
  349.     done > .Makefile.O_DEP.tmp ; \
  350.     mv .Makefile.O_DEP.tmp .Makefile.O_DEP ; \
  351.     for file in `cat /tmp/dependencies` ; do \
  352.       rm $$file ; \
  353.     done ; \
  354.     rm /tmp/dependencies ;
  355.  
  356.  
  357. source-dependencies : 
  358.     @ echo making source dependencies... ; \
  359.     ($(PROTOTYPE) -voutput_type=libg++-prototypes \
  360.         ../include/prototype.dependencies | \
  361.      gawk '($$1 !~ "_p.defs$$") || ($$1 == "char_p.defs") { print ; }' | \
  362.      PROTO_SOURCE=$(LPP) PP=LPP ../bin/make-source-dependencies ; \
  363.      ($(PROTOTYPE) -voutput_type=user-prototypes \
  364.         ../include/prototype.dependencies ; \
  365.       $(HIERARCHY) -voutput_type=general ../include/file_types.hierarchy) | \
  366.      PROTO_SOURCE=$(IPP) PP=IPP ../bin/make-source-dependencies ; \
  367.     ) > .Makefile.S_DEP ;
  368.  
  369. type-definitions :
  370.     @ echo make type definitions... ; \
  371.     $(MAKE_TYPES) > .Makefile.TYPES ;
  372.  
  373. #******************************************************************************
  374. # include machine generated dependencies 
  375.  
  376. include .Makefile.S_DEP
  377. include .Makefile.O_DEP
  378.